﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
using WeatherHistory.Api.Middlewares;

namespace WeatherHistory.Api.Configuration;

/// <summary>
///     Класс для настройки Middleware
/// </summary>
public static class MiddlewaresConfiguration
{
    /// <summary>
    ///     Настройка Middleware в приложении
    /// </summary>
    /// <param name="app">Ссылка на инстанс приложения</param>
    public static void ConfigureMiddlewares(this WebApplication app)
    {
        app.ConfigureSharedMiddlewares();
        app.ConfigureDevelopmentMiddlewares();
        app.ConfigureProductionMiddlewares();
    }

    private static void ConfigureSharedMiddlewares(this WebApplication app)
    {
        app.UseSwagger();
        app.UseSwaggerUI();
        app.UseDeveloperExceptionPage();

        app.UseMiddleware<ExceptionHandlerMiddleware>();
    }

    private static void ConfigureDevelopmentMiddlewares(this WebApplication app)
    {
        if (!app.Environment.IsDevelopment()) return;
    }

    private static void ConfigureProductionMiddlewares(this WebApplication app)
    {
        if (app.Environment.IsDevelopment()) return;
    }
}